﻿using System;
using System.Collections.Generic;
using System.Text;
using TileGert;

namespace TestApp.Tests
{
  class LineSegmentIntersection : TestGame
  {
    private GertLineSegment _seg1 = null;
    private GertLineSegment _seg2 = null;
    private GertPoint _intersection = null;

    protected override void AfterInit()
    {
      _seg1 = new GertLineSegment(300, 200, 500, 300);
      _seg2 = new GertLineSegment(400, 500, 400, 300);
    }

    protected override void Update(float timestep)
    {
      int step = 100;
      Input.Update();
      if (Input.Keyboard.KeyIsPressed(GertKeys.LeftArrow))
        _seg2.Point2.X -= step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.RightArrow))
        _seg2.Point2.X += step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.UpArrow))
        _seg2.Point2.Y -= step * timestep;
      if (Input.Keyboard.KeyIsPressed(GertKeys.DownArrow))
        _seg2.Point2.Y += step * timestep;

      _intersection = _seg1.Intersects(_seg2);
    }

    protected override void Render()
    {
      Renderer.Clear(GertColor.Navy);
      Renderer.Begin();

      Renderer.ForegroundColor = GertColor.White;
      Renderer.DrawLine(_seg1);
      Renderer.DrawLine(_seg2);

      if (_intersection != null)
      {
        Renderer.ForegroundColor = GertColor.Red;
        Renderer.DrawPoint(_intersection);
      }

      Renderer.End();
    }

  }
}
